'''
Copyright 2010 Indra Bagus <indra.bagus@gmail.com> 
    
Licensed under the Apache License, Version 2.0 (the "License"); 
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

    http://www.apache.org/licenses/LICENSE-2.0 
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. 
'''



from Dictionary import MACHeaderDict
from Type import WmxDictionaryValue, WmxIntegerValue


class MACSignallingTypeField:
    BR_INCREMENTAL              = 0x00
    BR_AGGREGATE                = 0x01
    PHY_CHANNEL_REPORT          = 0x02
    BR_WITH_UL_TX_POWER_REPORT  = 0x03 
    BR_AND_CINR_REPORT          = 0x04
    BR_WITH_UL_SLEEP_CONTROL    = 0x05
    SN_REPORT                   = 0x06
    CQICH_ALLOCATION_REQUEST    = 0x07






class EncodingTypeDL(object):
    def __init__(self):
        self.reserved                      = 0
        self.arq_feedback                  = WmxDictionaryValue(MACHeaderDict.encoding_type.arq_feedback)
        self.extended_type                 = WmxDictionaryValue(MACHeaderDict.encoding_type.extended_type)
        self.frag_subheader                = WmxDictionaryValue(MACHeaderDict.encoding_type.fragment_subheader)
        self.packing_subheader             = WmxDictionaryValue(MACHeaderDict.encoding_type.packing_subheader)
        self.fast_feedback_alloc_subheader = WmxDictionaryValue(MACHeaderDict.encoding_type.extended_type)
        
    def __int__(self):
        retval =   (self.reserved & 0x20)                      |\
                (self.arq_feedback.val & 0x10)              |\
                (self.extended_type.val & 0x08)             |\
                (self.frag_subheader.val & 0x04)            |\
                (self.packing_subheader.val & 0x02)             |\
                (self.fast_feedback_alloc_subheader.val & 0x01)
                
        return int(retval)
                
    
    def __str__(self):
        return str(self.__int__())



class MACHeaderGeneric(object) :
    '''
    The fields of the generic MAC header are defined in Table 5. Every header is encoded, 
    starting with the HT and encryption control (EC) fields. The coding of these fields 
    is such that the first byte of a MAC header shall never have the value of '0xFX', 
    where 'X' means 'do not care'. This prevents false detection on the
    stuff byte used in the transmission convergence sublayer (TCS).
    '''
    def __init__(self):
        self.header_type    = WmxIntegerValue(MACHeaderDict.header_type)
        self.encryption     = WmxIntegerValue(MACHeaderDict.encrytion_type)
        self.encoding_type  = EncodingTypeDL()
        self.esf            = WmxIntegerValue(MACHeaderDict.ext_subheader)
        self.crc_indicator  = WmxIntegerValue(MACHeaderDict.crc_indicator)
        self.eks            = WmxIntegerValue()
        self.reserved       = WmxIntegerValue()
        self.pdu_length     = WmxIntegerValue()
        self.cid            = WmxIntegerValue()
        self.hcs            = WmxIntegerValue()
        

 




class MACHeaderBWRequest(object) :
    def __init__(self):
        self.header_type = WmxDictionaryValue(MACHeaderDict.header_type)
        self.encryption = WmxDictionaryValue(MACHeaderDict.encoding_type)
        
        


